package com.xcjw.com.Utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @packname com.homeclient.com.Utils
 * @filename StringUtils
 * @date on 2018/9/3 10:29
 *****/
public class StringUtils {

            public StringUtils() {
            }

            public static boolean isBlank(CharSequence cs) {
                  int strLen;
                  if(cs != null && (strLen = cs.length()) != 0 && !cs.equals("null")) {
                        for(int i = 0; i < strLen; ++i) {
                              if(!Character.isWhitespace(cs.charAt(i))) {
                                    return false;
                              }
                        }

                        return true;
                  } else {
                        return true;
                  }
            }

            public static boolean isNotBlank(CharSequence cs) {
                  return !isBlank(cs);
            }

            public static boolean isSame(String str1, String str2) {
                  return isBlank(str1) && isBlank(str2)?true:!isBlank(str1) && !isBlank(str2) && str1.equals(str2);
            }

            public static boolean isPhone(String str) {
                  Pattern pattern = Pattern.compile("1[0-9]{10}");
                  Matcher matcher = pattern.matcher(str);
                  return matcher.matches();
            }

            public static boolean isEmailAddress(String str) {
                  Pattern pattern = Pattern.compile("^([0-9a-zA-Z\\._-])+@([0-9a-zA-Z]+\\.)+([a-zA-Z])+$");
                  Matcher matcher = pattern.matcher(str);
                  return matcher.matches();
            }

            public static boolean isDigitChar(String str) {
                  Pattern pattern = Pattern.compile("([0-9a-zA-Z])+");
                  Matcher matcher = pattern.matcher(str);
                  return matcher.matches();
            }

            public static String parseDistance(String distance) {
                  String result = "";
                  if(distance != null) {
                        Float dis = Float.valueOf(Float.valueOf(distance).floatValue() * 1000.0F);
                        result = String.valueOf(dis);
                        result = result.substring(0, result.indexOf(".")) + "米";
                  }

                  return result;
            }

            public static String getValidTelNumber(String telNumber) {
                  String str = telNumber.replace(" ", "");
                  str = str.replace("-", "");
                  str = str.replace("+86", "");
                  Pattern p = Pattern.compile("^((13[0-9])|(15[0-9])|(18[0-9]))\\d{8}$");
                  Matcher m = p.matcher(str);
                  return m.matches()?str:null;
            }

            public static String format(String s) {
                  String str = s.replaceAll("[`~!@#$%^&*()+=|{}\':;\',\\[\\].<>/?~！@#￥%……& amp;*（）——+|{}【】‘；：”“’。，、？|-]", "");
                  return str;
            }
}